package com.example.base.net

import com.example.base.entity.AddAddressEntity
import com.example.base.entity.AddCarEntity
import com.example.base.entity.CarEntity
import com.example.base.entity.CategoryEntity
import com.example.base.entity.CreateOrderEntity
import com.example.base.entity.GetPreOrderEntity
import com.example.base.entity.GoodsEntity
import com.example.base.entity.IndexEntity
import com.example.base.entity.LoginEntity
import com.example.base.entity.OrderEntity
import com.example.base.entity.PayEntity
import com.example.base.entity.PreOrderEntity
import com.example.base.entity.QuanEntity
import com.example.base.entity.Res
import com.example.base.entity.SendCodeEntity
import com.example.base.entity.UploadEntity
import com.example.base.entity.UserEntity
import com.example.base.entity.XqEntity
import com.example.base.param.ParamAddAddress
import com.example.base.param.ParamCreateOrder
import com.example.base.param.ParamPay
import com.example.base.param.ParamPreOrder
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query


interface ApiServer {
    //发送验证码
    @POST(Cons.SEND_CODE_URL)
    suspend fun sendCode(@Query(Cons.PARAM_PHONE) phone:String):Res<SendCodeEntity>
    @POST(Cons.LOGIN_CODE_URL)
    suspend fun loginCode(@Body body:RequestBody):Res<LoginEntity>
    @GET(Cons.USER_URL)
    suspend fun user():Res<UserEntity>
    @POST(Cons.UPDATE_URL)
    suspend fun update(@Body body: RequestBody):Res<Boolean>
    //首页数据
    @GET(Cons.INDEX_URL)
    suspend fun index():Res<IndexEntity>
    //首页商品数据  请求路径存在{}   参数中会有@Path注解
    @GET(Cons.INDEX_GOODS_URL)
    suspend fun indexGoods(@Path("type")type:Int,@Query("limit")limit:Int,@Query("page")page:Int):Res<GoodsEntity>
    //实现搜索
    @GET(Cons.GOODS_URL)
    suspend fun search(@Query("keyword")keyword:String,@Query("limit")limit:Int,@Query("page")page:Int):Res<GoodsEntity>
    //优惠券列表
    @GET(Cons.QUAN_URL)
    suspend fun quan(@Query("limit")limit:String,@Query("page")page:String,@Query("type")type:String):Res<QuanEntity>
    @POST(Cons.QUAN_RECEIVE_URL)
    suspend fun quanReceive(@Body body: RequestBody):Res<String?>
    //新增地址
    @POST(Cons.ADD_ADDRESS_URL)
    suspend fun addAddress(@Body paramAddAddress: ParamAddAddress):Res<AddAddressEntity>
    //商品详情
    @GET(Cons.XQ_URL)
    suspend fun xq(@Path("id")id:Int,@Query("type")type:String):Res<XqEntity>
    @POST(Cons.ADD_CAR_URL)
    suspend fun addCar(@Body body: RequestBody):Res<AddCarEntity>
    //购物车列表
    @GET(Cons.CAR_URL)
    suspend fun car(@Query("isValid")isValid:String,@Query("limit")limit:String,@Query("page")page:String):Res<CarEntity>
    //修改购物车
    @POST(Cons.UPDATE_CAR_URL)
    suspend fun updateCar(@Query("id")id:Int,@Query("number")number:Int):Res<String?>
    //删除购物车
    @POST(Cons.DELETE_CAR_URL)
    suspend fun deleteCar(@Query("ids")ids:Array<Int>):Res<String?>
    @GET(Cons.CATEGORY_URL)
    suspend fun category():Res<CategoryEntity>
    @GET(Cons.GOODS_URL)
    suspend fun cateXq(@Query("cid")cid:Int,@Query("keyword")keyword:String,@Query("limit")limit:Int,
                       @Query("news")news:Boolean,@Query("page")page:Int,@Query("priceOrder")priceOrder:String,@Query("salesOrder")salesOrder:String):Res<GoodsEntity>
    @POST(Cons.PREORDER_URL)
    suspend fun preOrder(@Body paramPreOrder: ParamPreOrder):Res<PreOrderEntity>
    @GET(Cons.GETPREORDER_URL)
    suspend fun getPreOrder(@Path("preOrderNo")preOrderNo:String):Res<GetPreOrderEntity>
    @POST(Cons.CREATEORDER_URL)
    suspend fun createOrder(@Body paramCreateOrder: ParamCreateOrder):Res<CreateOrderEntity>
    @POST(Cons.PAY_URL)
    suspend fun pay(@Body paramPay: ParamPay):Res<PayEntity>
    @GET(Cons.ORDER_URL)
    suspend fun order(@Query("type")type:String,@Query("limit")limit:Int,@Query("page")page:Int):Res<OrderEntity>

    //上传文件
    @Multipart
    @POST(Cons.UPLOAD_URL)
    suspend fun upload(@Query("model")model:String,@Part part: MultipartBody.Part,@Query("pid") pid:String):Res<UploadEntity>
}